package com.soccertgc.data.adapters
{
	import com.soccertgc.logging.LogLevel;
	import com.soccertgc.logging.LogTargetParams;
	import com.soccertgc.logging.LogTargetType;

	public class LogTargetParamsAdapter
	{

		public static function fromXML(xml:XML):LogTargetParams
		{
			// Create new configurtion
			var params:LogTargetParams = new LogTargetParams();
			// Safe exec
			try
			{
				// Params
				params.type				= LogTargetType.getByName(xml.@type);
				params.level 			= LogLevel.getByName(xml.level);
				params.showLevel		= Boolean(xml.showLevel);
				params.showDate			= Boolean(xml.showDate);
				params.showTime			= Boolean(xml.showTime);
				params.dateFormat		= xml.dateFormat;
				params.timeFormat		= xml.timeFormat;
				// Filters
				for each (var filter:XML in xml.filters.filter)
				{
					params.filters.push(filter);
				}
			}
			// Unexpected exception
			catch (e:Error)
			{
				throw new Error("LogTargetParamsAdapter.fromXML() unexpected error: " + e.toString());
			}
			return params;
		}
		
	}
}